-- town4 - "Grimsby"

function autoexec()
  if (get_progress(P_CARAVEL) < 1 or get_progress(P_CARAVEL) == 2) then 
    LOC_move_caravel()
    set_ent_active(4,0)
   
  end
  

  if (get_progress(P_CHORES) <= 6 or get_progress(P_REBELLION ) >= 1) then 
    LOC_remove_ship()
    set_ent_active(5,0)
  end
    

  if (get_progress(P_CARAVEL) == 4) then
    set_ent_chrx(HERO1, 0);
    if (get_numchrs() == 2) then
      set_ent_chrx(HERO2, 0);
    end
    set_progress(P_CARAVEL,1);
  end
 
  LOC_night() 
end

function refresh()
  return
end

function postexec()


end

function zone_handler(zn)
  if (zn == 1) then
    change_map("land","grimsby_exit");

  elseif (zn == 2) then
    door_in("inn_enter")

  elseif (zn == 3) then    
    door_in("w_in")

  elseif (zn == 4) then    
    door_in("store_in")

  elseif (zn == 5) then    
    door_in("hall_in")

  elseif (zn == 6) then
    thought(en,"Its locked.");

  elseif (zn == 7) then
  
  elseif (zn == 8) then
    door_in("ware_in")

  elseif (zn == 9) then
 
  elseif (zn == 10) then
    if (get_progress(P_SPLASH) < 1) then
      msg("SPLASH", 255, 0);
      set_progress(P_SPLASH,1);
    end  

  elseif (zn == 11) then
    chest(17, I_OCEANPEARL, 1)

  elseif (zn == 12) then
    warp("inn1_up",8)

  elseif (zn == 13) then
    warp("inn2_dn",8)

  elseif (zn == 14) then
    book_talk(get_pidx(0));

  elseif (zn == 15) then
    door_out("inn_x")

  elseif (zn == 16) then
    inn("Seaside Inn", 30, 1)

  elseif (zn == 17) then
    door_out("ware_exit")

  elseif (zn == 18) then
    door_out("w_exit")

  elseif (zn == 19) then
    door_out("hall_exit")

  elseif (zn == 20) then
    door_out("store_exit")	
  
  elseif (zn == 21) then
    touch_fire(get_pidx(0));

  elseif (zn == 22) then
    bubble(11, "Welcome to the town hall of Grimsby.");

  elseif (zn == 23) then
    shop(20)

  elseif (zn == 24) then
    shop(13)
  
  end
end

function entity_handler(en)
  if (en == 0) then
    if (get_progress(P_CHORES) <= 6) then
      bubble(en, "Its not good for a sailor to be without a ship.");
    else
      bubble(en,"This here ship is the trading galleon Wave Runner, all the way from Lanaerta.");
    end
    
  elseif (en == 1) then
    bubble(HERO1,"Do many ships come through here?");
    bubble(en,"A fair amount for how remote this island is.");


  elseif (en == 2) then 
    bubble(en,"I like flowers. Do you like flowers?");
    bubble(HERO1,"Hmm I haven't put much thought to it before.");
    bubble(HERO1,"There alright I suppose."); 

  elseif (en == 3) then
    bubble(en,"Mother doesn't like us to play near the docks.")
    bubble(en,"So we play around the fire pit just north a' here.")
    bubble(en,"I like to go swimming up there, where the water isnt so deep.")

  elseif (en == 4) then
    if (prompt(en,2,0,"Would you like to take a ride to the island of Thessalia for a mere 250 gold?","  yes","  no","") == 0) then 
      if (get_gp() < 250) then
        bubble(en,"Ya trying to cheat me. Thats not enough gold.");
      elseif (get_gp() >= 250) then
        set_gp(get_gp() - 250)
        msg("You pay Captain Finch 250 gold.")
        bubble(en,"Alright let's set sail.");
        set_ent_chrx(HERO1, 34)
        if (get_numchrs() == 2) then
          set_ent_chrx(HERO2, 98)
        end
        change_map("land","harbor_exit");
        set_progress(P_CARAVEL,2);  
      end 
    else
      bubble(en,"Well come back by another time.");
    end
  

  elseif (en == 5) then
--if (get_progress(P_CHORES) <= 6 or get_progress(P_REBELLION ) >= 1) then 
    bubble(en,"Hallo sir.");
    bubble(HERO1,"You're not from around here, are you?");
    bubble(en,"No I'm a sailor on board the mighty trading galleon the Wave Runner. Our operations are based out of Lanaerta, a good long voyage from here. I like to come here for a good drink whenever we port here in Grimsby."); 
    bubble(HERO1,"So do you have any news from your journeys?");
    bubble(en,"Hmm well there has been word that the Kingdom of Eruthraia has been completely overun by the Marauders from Dresgoth. The Marauders were merciless and left few survivors in their conquest. The cause of the invasion is unknown but their are many whispers of some dark secret... but alas I know no more concerning the tale.");

  elseif (en == 6) then
if (get_progress(P_CHORES) <= 6 or get_progress(P_REBELLION ) >= 1) then
    bubble(en,"Ahh theres nothing like a good ale to help you relax after a long day's work.");
    bubble(HERO1,"What is it exactly that you do for work?");
    bubble(en,"A little of this and a little of that, you know?");
    bubble(HERO1,"I see."); 
   
else
    bubble(en,"The life of sailor is not for me. Too much travelling and adventure for me.");
    bubble(5,"You're such a scoundrel, Jacob. It's really because he can't set foot on a boat without losing his breakfast.");
    bubble(en,"Hmph.");
end

  elseif (en == 7) then
    shop(20);
	
  elseif (en == 8) then
    shop(13);

  elseif (en == 9) then
    bubble(en,"Hello there.");

  elseif (en == 10) then
    
  elseif (en == 11) then
    bubble(en,"This is the town hall.");

  elseif (en == 12) then
    bubble(en,"This is a warehouse used to store the goods between shipments.");

end  
       end 

--changes the tiles to make the ship and caravel to disappear respectively.
function LOC_remove_ship()

--front tiles
set_obs("s5",1)
set_btile("s5", 160)--716

--middle tiles 
set_mtile("s1", 000) --698
set_mtile("s2", 000) --697
set_mtile("s3", 000) --695
set_mtile("s4", 000) --696
set_mtile("s6", 000) --695
set_mtile("s7", 000) --696
set_mtile("s8", 000) --694
set_mtile("s9", 000) --693
set_mtile("s10", 000)--679
set_mtile("s11", 000)--678
set_mtile("s12", 000)--677
set_mtile("s13", 000)--676
set_mtile("s14", 000)--676
set_mtile("s15", 000)--676
set_mtile("s16", 000)--676
set_mtile("s17", 000)--675
set_mtile("s18", 000)--674
set_mtile("s19", 000)--673
set_mtile("s20", 000)--681
set_mtile("s21", 000)--680
set_mtile("s25", 000)--688
set_mtile("s26", 000)--680
set_mtile("s27", 000)--672
set_mtile("s28", 000)--671
set_mtile("s32", 000)--686

--back tiles 
set_ftile("s12", 000)--682
set_ftile("s14", 000)--690
set_ftile("s16", 000)--690
set_ftile("s17", 000)--682
set_ftile("s20", 000)--692
set_ftile("s21", 000)--691

set_ftile("s22", 000)--689
set_ftile("s23", 000)--688
set_ftile("s24", 000)--689
set_ftile("s25", 000)--681

set_ftile("s42", 000)--713
set_ftile("s43", 000)--712
set_ftile("s29", 000)--687
set_ftile("s30", 000)--686
set_ftile("s31", 000)--687
set_ftile("s32", 000)--713
set_ftile("s33", 000)--712
set_ftile("s34", 000)--685
set_ftile("s35", 000)--684
set_ftile("s36", 000)--685
set_ftile("s37", 000)--684
set_ftile("s38", 000)--683
set_ftile("s39", 000)--714 or 715
set_ftile("s40", 000)--683
set_ftile("s41", 000)--714 or 715

end


function LOC_move_caravel()

--front tiles
set_obs("c3",1)
set_btile("c3", 160)

--middle tiles 
set_mtile("c1", 000)
set_mtile("c2", 000)
set_mtile("c4", 000)
set_mtile("c5", 000)
set_mtile("c6", 000)
set_mtile("c7", 000)
set_mtile("c8", 000)
set_mtile("c9", 000)
set_mtile("c10", 000)
set_mtile("c11", 000)
set_mtile("c12", 000)
set_mtile("c13", 000)
set_mtile("c14", 000)
set_mtile("c15", 000)
set_mtile("c16", 000)
set_mtile("c17", 000)
set_mtile("c18", 000)
set_mtile("c20", 000)


--back tiles 
set_ftile("c26", 000)
set_ftile("c10", 000)
set_ftile("c11", 000)
set_ftile("c14", 000)
set_ftile("c15", 000)
set_ftile("c19", 000)
set_ftile("c20", 000)
set_ftile("c21", 000)
set_ftile("c22", 000)
set_ftile("c23", 000)
set_ftile("c24", 000)
set_ftile("c25", 000)


end

function LOC_night()
--changes every tiles shadow to night.

  local y=54
  local x=0
 
while (y > 0) do
   x=0
  while (x < 73) do 
    set_shadow(x, y, 8)
    x=x+1
  end
  y=y-1
end

end
